package cn.sunxinao.pm.models;

import java.io.Serializable;
import java.util.Objects;

public abstract class AbstractPet implements Serializable {
    private static final long serialVersionUID = 5341674873791738127L;

    /**
     * 编号
     */
    protected long id;

    /**
     * 名字
     */
    protected String name;

    /**
     * 性别(false = male; true = female)
     */
    protected boolean sex;

    /**
     * 年龄
     */
    protected float age;

    /**
     * 类型
     */
    protected String type;

    /**
     * 颜色
     */
    protected String color;

    /**
     * 入所时间
     */
    protected String joinDate;

    /**
     * 领养人
     */
    protected String owner;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isSex() {
        return sex;
    }

    public void setSex(boolean sex) {
        this.sex = sex;
    }

    public float getAge() {
        return age;
    }

    public void setAge(float age) {
        this.age = age;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(String joinDate) {
        this.joinDate = joinDate;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String display() {
        String delimiter = ",\t";
        return id + delimiter +
            name + delimiter +
            (sex ? "雌" : "雄") + delimiter +
            age + delimiter +
            type + delimiter +
            color + delimiter +
            joinDate + delimiter +
            owner;
    }

    @Override
    public String toString() {
        return "Pet{" +
            "id=" + id +
            ", name='" + name + '\'' +
            ", sex=" + sex +
            ", age=" + age +
            ", type='" + type + '\'' +
            ", color='" + color + '\'' +
            ", joinDate='" + joinDate + '\'' +
            ", owner='" + owner + '\'' +
            '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof AbstractPet)) return false;
        AbstractPet pet = (AbstractPet) o;
        return id == pet.id &&
            sex == pet.sex &&
            Float.compare(pet.age, age) == 0 &&
            Objects.equals(name, pet.name) &&
            Objects.equals(type, pet.type) &&
            Objects.equals(color, pet.color) &&
            Objects.equals(joinDate, pet.joinDate) &&
            Objects.equals(owner, pet.owner);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, sex, age, type, color, joinDate, owner);
    }
}
